#!/usr/bin/env python
# encoding: utf-8
""" 
参数验证
"""
import sys
sys.path.append("..")
import const
import json

async def ParamsVerifyMiddleware(context):
    """ """
    payload = json.loads(context.request.body)

    if "method" not in payload: 
        return {
            "code":const.ERR_PARAMETER_LOST,
            "msg":"can not find method field"
        }
    if payload["method"] not in context.router._method_mapping:
        return {
            "code":const.ERR_METHOD_NOT_FOUND,
            "msg":"reply from default method"
        }
    if "token" not in payload:
        return {
            "code":const.ERR_PARAMETER_LOST,
            "msg":"can not find token field"
        }
    return await context.next()